package program.Condition;

import program.SExpression;
import roborally.Element;
import roborally.Item;
import roborally.Robot;

/**
 * A class representing an AT ITEM condition.
 * 
 * @author Jef Keijers/Bachelor of Science: Informatics
 * @version 1.0
 */

public class AtItem extends Condition {

	/**
	 * This method returns true if the condition of the next command in the robot's memory is true, otherwise it returns false.
	 */
	@Override
	public boolean execute(Robot robot) {
		for (Element element: robot.getBoard().getPositionMap().get(robot.getPosition())) {
			if (element instanceof Item) 
				return true;
		}
		return false;
	}

	/**
	 * This method returns the SExpression representation of at-item.
	 */
	@Override
	public SExpression toSExpression() {
		return this.makeSingletonSExpressionList("at-item");
	}
}
